package com.yuanli.cosmeticmirror.view.activity;

import android.os.Bundle;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.yuanli.cosmeticmirror.R;
import com.yuanli.cosmeticmirror.base.BaseActivity;
import com.yuanli.cosmeticmirror.bean.TutorialBean;
import com.yuanli.cosmeticmirror.bean.TutorialTypeBean;
import com.yuanli.cosmeticmirror.model.iview.ITutorialView;
import com.yuanli.cosmeticmirror.persenter.TutorialPersenter;
import com.yuanli.cosmeticmirror.view.adapter.FmPagerAdapter;
import com.yuanli.cosmeticmirror.view.fragment.TutorialFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 教程
 */
public class TutorialActivity extends BaseActivity implements ITutorialView {
    @BindView(R.id.tutorial_back)
    ImageView tutorialBack;
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private FmPagerAdapter pagerAdapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private List<String> titles = new ArrayList<>();
    private TutorialPersenter persenter;

    @Override
    protected int getContentView() {
        return R.layout.activity_tutorial;
    }

    @Override
    protected void init(Bundle bundle) {
        persenter = new TutorialPersenter(this, this);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        persenter.getTutorialType();
    }

    @Override
    protected void destroy() {
    }


    @OnClick(R.id.tutorial_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onSucess(TutorialBean bean) {
    }

    @Override
    public void error() {
    }

    @Override
    public void onTypeSuccess(TutorialTypeBean object) {
        for (int i = 0; i < object.getData().size(); i++) {
            titles.add(object.getData().get(i).getType());
            fragments.add(new TutorialFragment(i, object.getData().get(i).getId()));
            tabLayout.addTab(tabLayout.newTab());
        }
        tabLayout.setupWithViewPager(viewPager, false);
        pagerAdapter = new FmPagerAdapter(fragments, titles, getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);
        //        if (MyApp.getPhotoFrameStatus().fragmentIndex != -1) {
        //            viewPager.setCurrentItem(MyApp.getPhotoFrameStatus().fragmentIndex);
        //        }
    }
}
